package com.scuec.tourismwebsite.controller;

import com.scuec.tourismwebsite.entity.Message;
import com.scuec.tourismwebsite.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("tour/v1")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @GetMapping("messages")
    public List<Message> getAllMessages() {
        return messageService.getAllMessages();
    }

    @PostMapping("messages")
    public String addMessage(@RequestBody Message message) {
        messageService.addMessage(message.getContent());
        return "Message added successfully!";
    }
}
